﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace _6.RecursiveFilesFoldersCopy.Model
{
    public static class CopyHelper
    {
        public static void CopyFilesAndDirsRecursively(string sourceDirName, string destinationDirName)
        {
            // copy files
            foreach (string fileName in Directory.GetFiles(sourceDirName))
            {
                string destinationFileName = destinationDirName 
                    + Path.DirectorySeparatorChar 
                    + Path.GetFileName(fileName);

                File.Copy(fileName, destinationFileName);
            }

            // create dirs and copy files and subdirs
            foreach (string subDir in Directory.GetDirectories(sourceDirName))
            {
                // create dir with same name
                string destinationSubDirName = destinationDirName 
                    +  Path.DirectorySeparatorChar 
                    + Path.GetFileName(subDir);

                Directory.CreateDirectory(destinationSubDirName);

                // copy files and subfolders                
                CopyFilesAndDirsRecursively(subDir, destinationSubDirName);
            }
        }
    }
}
